package com.zjg.vue_cms.interceptor;

import cn.hutool.jwt.JWT;
import cn.hutool.jwt.JWTUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author guass
 * @date 2022年04月16日 16:11
 */
@Slf4j
@Component
public class BaseInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("token");

        log.info("guass token {} {}", token, request.getRequestURI());
        if (false) {
            return true;
        } else {
            log.info("guass token {}", token);
            JWT parseToken = JWTUtil.parseToken(token);

            log.info("guass {}", parseToken);


            if (parseToken != null) {
                return true;
            }
        }
//
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        return false;
    }
}
